package com.dyna.demo.excel.controller;

import com.dyna.demo.excel.domain.dto.Student;
import com.dyna.demo.excel.service.ExcelService;
import com.dyna.domain.resp.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * demo模块/demo/excel相关功能
 * @author zhoucaiwang
 * @date 2024/3/20
 */

@RestController
@RequestMapping("/excel")
public class ExcelController {

    @Resource
    private ExcelService excelService;

    @ApiOperation(value = "导出excel")
    @GetMapping("/exportByTemplate")
    public void exportByTemplate(@RequestParam(value = "result", required = false) String result) {
        excelService.exportByTemplate(result);
    }

    @ApiOperation(value = "不使用模板导出excel", notes = "直接通过响应流返回")
    @GetMapping("/exportByStream")
    public void exportByStream(HttpServletResponse response) {
        excelService.exportByStream(response);
    }

    @ApiOperation(value = "读取excel")
    @PostMapping("/readExcel")
    public R<List<Student>> readExcel(MultipartFile file) {
        return R.data(excelService.readExcel(file));
    }

    @ApiOperation("合并单元格")
    @GetMapping("/merge")
    public void merge(HttpServletResponse response) {
        excelService.merge(response);
    }

}





